package com.wuyou.designPatterns.state;

import com.sun.org.glassfish.external.statistics.Stats;

/**
 * 表示白天的类
 *
 * @Date 2024/10/17 11:02
 * @Author 无忧
 */
public class DayState implements State {

    // 如果每次状态发生改变时都生成一个实例的话，会很浪费内存和时间
    private static DayState singleton = new DayState();

    private DayState(){}

    public static State getInstance(){
        return singleton;
    }

    @Override
    public void doClock(Context context, int hour) {
        if(hour < 9 || hour > 17){
            context.changeState(NightState.getInstance());
        }
    }

    @Override
    public void doUse(Context context) {
        context.recordLog("使用金库(白天)");
    }

    @Override
    public void doAlarm(Context context) {
        context.callSecurityCenter("按下警铃(白天)");
    }

    @Override
    public void doPhone(Context context) {
        context.callSecurityCenter("正常通话(白天)");
    }

    public String toString(){
        return "[白天]";
    }
}
